package com.minyifang.wcspf.work.ui.user.activities;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.minyifang.wcspf.R;
import com.minyifang.wcspf.common.adapter.GeneralFragmentPagerAdapter;
import com.minyifang.wcspf.common.base.BaseActivity;
import com.minyifang.wcspf.work.ui.home.fragments.home2sub.SubClassFragment;
import com.minyifang.wcspf.work.ui.user.fragments.OrderListFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class MyOrderListActivity extends BaseActivity {

    public static final String EXTRA_TYPE = "type";

    @BindView(R.id.tl_class)
    TabLayout mTabLayout;
    @BindView(R.id.vp_class)
    ViewPager mViewPager;

    List<String> titles = new ArrayList<>();
    List<Fragment> mFragments = new ArrayList<>();
    String[] types = {"", "0", "6", "2"};
    private int mType; //0待付款、1待取货、2待收货、3订单完成、4订单取消、5订单退货.6待发货

    public static void start(Context context, int type) {
        Intent intent = new Intent(context, MyOrderListActivity.class);
        intent.putExtra(EXTRA_TYPE, type);
        context.startActivity(intent);
    }

    @Override
    protected int setContentLayoutRes() {
        return R.layout.activity_my_order_list;
    }

    @Override
    protected void initView() {
        mType = getIntent().getIntExtra(EXTRA_TYPE, 0);
    }

    @Override
    protected void initData() {
        titles.add("全部");
        titles.add("待付款");
        titles.add("待发货");
        titles.add("待收货");
        for (int i = 0; i < titles.size(); i++) {

            OrderListFragment fragment = new OrderListFragment();
            Bundle bundle = new Bundle();
            bundle.putString("type", types[i]);
            fragment.setArguments(bundle);
            mFragments.add(fragment);
        }

        mViewPager.setAdapter(new GeneralFragmentPagerAdapter(getSupportFragmentManager(), mFragments, titles));
        mViewPager.setOffscreenPageLimit(titles.size());
        mTabLayout.setupWithViewPager(mViewPager);

        switch (mType) {
            case 0:
                mViewPager.setCurrentItem(0);
                break;
            case 1:
                mViewPager.setCurrentItem(1);
                break;
            case 2:
                mViewPager.setCurrentItem(2);
                break;
            case 3:
                mViewPager.setCurrentItem(3);
                break;

        }
    }
}
